package com.zhida84.Impl;
/**
 * 
 * @author shazhengbo sunchangxing
 *
 */
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zhida84.Dao.DBSQL;
import com.zhida84.Dao.RecruitDao;

public class RecruitImpl implements RecruitDao {
	DBSQL db = new DBSQL();

	@Override
	public ResultSet IndexDateList(int Incremental) {
		String sql = "select * from recruittable where activeTF='未完结'  order by  recruitId desc limit ?,10";
		return db.getQuery(sql, new Object[] { Incremental });
	}
	
	@Override
	public ResultSet detailsDateList(int recruitId) {
		String sql = "select * from recruittable left join merchanttable on  recruittable.merId=merchanttable.merId where recruitId=?";
		return db.getQuery(sql, new Object[] { recruitId });
	}

	@Override
	public ResultSet searchRescruit(String strQuery) {
		String sql = strQuery;
		return db.getQuery(sql, null);
	}

	@Override
	public ResultSet multipleChoice(String sex, String summary, int num) {
		if (sex == "²»ÏÞ") {
			String sql = "select * from recruittable where activeTF='Î´Íê½á' and  actType=? limit ?,10";
			return db.getQuery(sql, new Object[] { summary, num });
		} else if (summary == "²»ÏÞ") {
			String sql1 = "select * from recruittable where activeTF='Î´Íê½á' and reSex=? limit ?,10";
			return db.getQuery(sql1, new Object[] { sex, num });
		} else {
			String sql1 = "select * from recruittable where activeTF='Î´Íê½á' and reSex=? and actType=? limit ?,10";
			return db.getQuery(sql1, new Object[] { sex, summary, num });
		}
	}

	@Override
	public ResultSet getonlySex(String value, int num) {
		String sql = "select * from recruittable where activeTF='Î´Íê½á' and reSex=? limit ?,10";
		return db.getQuery(sql, new Object[] { value, num });
	}

	@Override
	public ResultSet getonlySummary(String value, int num) {
		String sql = "select * from recruittable where activeTF='Î´Íê½á' and actType=? limit ?,10";
		return db.getQuery(sql, new Object[] { value, num });
	}

	@Override
	public ResultSet byUserIdSearch(String applycheck, int userId, int num) {
		String sql = "select * from applytable,recruittable where recruittable.recruitId=applytable.recruitId  and activeTF='Î´Íê½á' and applyCheck=? and userId=? limit ?,10";
		return db.getQuery(sql, new Object[] { applycheck, userId, num });
	}

	@Override
	public ResultSet byUserIdActiveTF(String activeTF, int userId, int num) {
		String sql = "select * from applytable,recruittable where recruittable.recruitId=applytable.recruitId and applyCheck !='±»¾Ü¾ø' and activeTF=? and userId=? limit ?,10";
		return db.getQuery(sql, new Object[] { activeTF, userId, num });
	}

	@Override
	public ResultSet bySearchType(String type) {
		String sql="select * from recruittable where  reType=? and activeTF='未完结'";
		return db.getQuery(sql, new Object[]{type});
	}

	@Override
	public ResultSet byUserIdSearchLead(String sql) {
		return db.getQuery(sql,null);
	}

	@Override
	public int sendMsgInfo(Integer userId, Integer recruitId, String msg) {
		String sql="INSERT INTO messagetable(recId ,userId,contentInfo) VALUES (?,?,?);";
		// 新增，修改，删除调用getUpdate方法
		return db.getUpdate(sql,new Object[] {recruitId,userId, msg});
	}

	@Override
	public int collectionInfo(Integer userId, Integer recruitId) {
		String isExist = "select id from collectiontable where userId= ? and recId = ?";
		ResultSet query = db.getQuery(isExist, new Object[] {userId,recruitId});
		try {
			if (query.next()) {
				return 0;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		String sql="INSERT INTO collectiontable(userId ,recId) VALUES (?,?);";
		return db.getUpdate(sql,new Object[] {userId,recruitId});
	}
}
